package  com.rboat.exam.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rboat.common.annotation.Log;
import com.rboat.common.enums.BusinessType;
import com.rboat.exam.domain.ExamTestPaperChapter;
import com.rboat.exam.service.IExamTestPaperChapterService;
import com.rboat.common.core.controller.BaseController;
import com.rboat.common.core.domain.AjaxResult;
import com.rboat.common.utils.poi.ExcelUtil;
import com.rboat.common.core.page.TableDataInfo;

/**
 * 考试试卷章节Controller
 * 
 * @author rboat
 * @date 2019-09-02
 */
@Controller
@RequestMapping("/exam/chapter")
public class ExamTestPaperChapterController extends BaseController
{
    private String prefix = "exam/chapter";

    @Autowired
    private IExamTestPaperChapterService examTestPaperChapterService;

    @RequiresPermissions("exam:chapter:view")
    @GetMapping()
    public String chapter()
    {
        return prefix + "/chapter";
    }

    /**
     * 查询考试试卷章节列表
     */
    @RequiresPermissions("exam:chapter:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamTestPaperChapter examTestPaperChapter)
    {
        startPage();
        List<ExamTestPaperChapter> list = examTestPaperChapterService.selectExamTestPaperChapterList(examTestPaperChapter);
        return getDataTable(list);
    }

    /**
     * 导出考试试卷章节列表
     */
    @RequiresPermissions("exam:chapter:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamTestPaperChapter examTestPaperChapter)
    {
        List<ExamTestPaperChapter> list = examTestPaperChapterService.selectExamTestPaperChapterList(examTestPaperChapter);
        ExcelUtil<ExamTestPaperChapter> util = new ExcelUtil<ExamTestPaperChapter>(ExamTestPaperChapter.class);
        return util.exportExcel(list, "chapter");
    }

    /**
     * 新增考试试卷章节
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考试试卷章节
     */
    @RequiresPermissions("exam:chapter:add")
    @Log(title = "考试试卷章节", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamTestPaperChapter examTestPaperChapter)
    {
        return toAjax(examTestPaperChapterService.insertExamTestPaperChapter(examTestPaperChapter));
    }

    /**
     * 修改考试试卷章节
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ExamTestPaperChapter examTestPaperChapter = examTestPaperChapterService.selectExamTestPaperChapterById(id);
        mmap.put("examTestPaperChapter", examTestPaperChapter);
        return prefix + "/edit";
    }

    /**
     * 修改保存考试试卷章节
     */
    @RequiresPermissions("exam:chapter:edit")
    @Log(title = "考试试卷章节", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamTestPaperChapter examTestPaperChapter)
    {
        return toAjax(examTestPaperChapterService.updateExamTestPaperChapter(examTestPaperChapter));
    }

    /**
     * 删除考试试卷章节
     */
    @RequiresPermissions("exam:chapter:remove")
    @Log(title = "考试试卷章节", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examTestPaperChapterService.deleteExamTestPaperChapterByIds(ids));
    }
}
